/*
 * @(#)UserService.java 2013-4-6 下午08:34:35
 *
 * Copyright 2013 Beijing Axesline Technology Co..Ltd All rights reserved.
 * 该程序的所有权为北京铭扬谷地咨询有限公司.
 * 使用之前必须得到北京铭扬谷地咨询有限公司的许可;
 */
package com.minyond.demo.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.minyond.demo.entity.User;
import com.minyond.demo.repository.UserDao;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2013</p>
 * <p>Company: minyond</p>
 * <P>Created Date :2013-4-6</P> 
 * @author zhangfeng
 * @version 1.0
 */
@Component
@Transactional(readOnly = true)
public class UserService {
    
    private UserDao userDao;
    
    public List<User> getAllUser() {
        return (List<User>) userDao.findAll();
    }

    public User getUser(Long id) {
        return userDao.findOne(id);
    }

    public User findUserByLoginName(String loginName) {
        return userDao.findByLoginName(loginName);
    }

    @Transactional(readOnly = false)
    public void registerUser(User user) {
        user.setRegisterDate(new Date());
        user.setRoles("user");
        user.setSalt("430545");
        
        userDao.save(user);
    }

    @Transactional(readOnly = false)
    public void updateUser(User user) {        
        userDao.save(user);
    }

    @Transactional(readOnly = false)
    public void deleteUser(Long id) {       
        userDao.delete(id);        
    }
    
    @Autowired
    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }
}
